package com.haixiaoke.saas.order.state.role;

import com.haixiaoke.saas.common.constant.OrderConstants;
import com.haixiaoke.saas.common.enums.OrderStateEnum;
import com.haixiaoke.saas.order.domain.Order;
import com.haixiaoke.saas.order.state.server.IOrderStateServerRole;

/**
 * 退订中状态服务实现类
 * @author panda
 * @Date 2024/4/29
 **/
public class UnsubscribingOrderStateServerRole extends AbstractSpecificOrderOrderStateServerRole {

    public UnsubscribingOrderStateServerRole(IOrderStateServerRole stateServerRole) {
        super(stateServerRole);
    }

    @Override
    public int unsubscribeSuccessfully(Order order, String recordSource, String recordReason) {
        addOrderStateRecord(order.getOrderId(), order.getOrderState(), OrderStateEnum.ORDER_STATE_UNSUBSCRIBE_SUCCESSFULLY.getValue(), recordSource, recordReason, order.getOperatorId());
        order.setOrderState(OrderStateEnum.ORDER_STATE_UNSUBSCRIBE_SUCCESSFULLY.getValue());
        return orderService.updateOrderBySystem(order);
    }

    @Override
    public int unsubscribeFailureStayCheckIn(Order order, String remark) {
        addOrderStateRecord(order.getOrderId(), order.getOrderState(), OrderStateEnum.ORDER_STATE_STAY_CHECK_IN.getValue(), OrderConstants.RECORD_SOURCE_ENTERPRISE, remark, order.getOperatorId());
        order.setOrderState(OrderStateEnum.ORDER_STATE_STAY_CHECK_IN.getValue());
        return orderService.updateOrderBySystem(order);
    }
}
